package com.jianyun.jyzs.dao;

import android.content.Context;


import com.jianyun.jyzs.bean.QualityRespon;
import com.jianyun.jyzs.bean.SafeInsResponse;
import com.jianyun.jyzs.bean.WorkOrderDetialResponse;
import com.jianyun.jyzs.constant.SysConstant;
import com.jianyun.jyzs.utils.LoginCache;

/**
 * Created by mlli on 2017/12/9.
 * 处理应用页面的消息提示
 */

public class MessageRemind {
    private Context context;
    private final WorkOrderDao workOrderDao;
    private final QualityDao qualityDao;
    private final SecurityDao securityDao;
    private final ModelDao modelDao;
    private final String enterpriseCode;
    private final String userId;


    public MessageRemind(Context context) {
        this.context = context;
        workOrderDao = new WorkOrderDao(context);
        qualityDao = new QualityDao(context);
        securityDao = new SecurityDao(context);
        modelDao = new ModelDao(context);
        ModelDao dao = new ModelDao(context);
        enterpriseCode = LoginCache.getInstance().getLoginCache().getEnterpriseCode();
        userId = LoginCache.getInstance().getUserInfo().getUserId();
        for (int i = 0; i < SysConstant.img_list.length; i++) {
            dao.insert(new ItemModel(SysConstant.top_title[i],SysConstant.img_list[i],false,0, userId, enterpriseCode,0));
        }
        for (int i = 0; i < SysConstant.menu_list.length; i++) {
            dao.insert(new ItemModel(SysConstant.menu_title[i],SysConstant.menu_list[i],false,0, userId, enterpriseCode,1));
        }
    }

    //根据消息的讨论组ID 查找是属于哪个应用条目
    public  void handlerDiscussion(String disId){
        String title =null;
        WorkOrderDetialResponse.WorkOrder workOrder = workOrderDao.getOrderByDisId(disId);
        if (workOrder!=null){
            workOrder.setUnRead(true);
            title = "工单";
            workOrderDao.insert(workOrder);
        }
        QualityRespon.QualityRes qualityRes = qualityDao.getQualityByDisId(disId);
        if (qualityRes!=null){
            qualityRes.setUnRead(true);
            title = "质量检查";
            qualityDao.insert(qualityRes);
        }
        SafeInsResponse.SafeBean safeBean = securityDao.getSafeByDisId(disId);
        if (safeBean!=null){
            title = "安全检查";
            safeBean.setUnRead(true);
            securityDao.insert(safeBean);
        }
        if (title!=null){
            ItemModel model = modelDao.getModel(userId, enterpriseCode, title);
            model.setUnRead(true);
            modelDao.update(model);
        }
        //EventBus.getDefault().post(new PushEvent(4));


    }
}
